home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 June
/
EnigmA AMIGA RUN 19 (1997)(G.R. Edizioni)(IT)[!][issue 1997-06][EAR-CD III].iso
/
games
/
interactivefiction
/
agt
/
source
/
agtread.h
next >
Wrap
C/C++ Source or Header
|
1996-10-25
|
23KB
|
673 lines
/* agtread.h-- Header for all AGiliTy files. */
/* Copyright 1996 Robert Masenten */
/* */
/* This is part of the source for AGiliTy: the (Mostly) Universal */
/* AGT Interpreter */
/*
This is the master header file for all of the AGT stuff.
It includes the global variables, the data types, etc.
(everything that is read in from the game file).
Variables not read in from the game file but used internally
by the interpreter are declared in uagt.h.
This file also contains most of the configuration information
including the platform-dependent #define statements
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef global /* Don't touch this */
#define global extern
#define global_defined_agtread
#endif
#ifdef __MSDOS__ /* This works under Borland C, at least */
#define MSDOS
#endif
/* ------------------------------------------------------------------- */
/* PLATFORM SPECIFIC DEFINITIONS, ETC. */
/* Things you can currently define: */
/* fix_ascii: 1=translate IBM character set, 0=don't */
/* NEED_STR_CMP: define if strcasecmp() not defined on your system */
/* NEED_STRN_CMP: define if strncasecmp() not defined on your system */
/* HAVE_STRDUP: define if strdup() exists on your system */
/* REPLACE_GETFILE: define if you replace the default get_user_file(). */
/* REPLACE_MENU if you replace agt_menu(). */
/* REPLACE_MAIN: define if you replace the default main(). */
/* (replacements should be defined in the relevant os_<platform>.c file) */
/* DA1,DA2,...DA6,DSS,pTTL: file name extensions for the various AGT
files */
/* HAVE_SLEEP if your platform has the sleep() function */
/* BUFF_SIZE is the maximum size of the buffer to use when reading
in files. Regardless, it will be made no bigger than the file
being read in and no smaller than the record size; thus setting
it to 0 will cause the smallest buffer to always be used and
setting this to 1MB will in practice always use a buffer the
sizs of the file. It defaults to 32K */
/* CBUF_SIZE is the maximum size of the buffer used for reading in
the Master's Edition DA6 files; the size of the buffer in bytes
is twice this value (since an individual token is two bytes long). */
/* DOHASH to use a hash table for dictionary searches; the only
reason not to have this would be memory */
/* HASHBITS determines the size of the hash table: (2^HASHBITS)*sizeof(word);
the hash table must be at least as large as the dictionary.
In practice this means HASHBITS must be at least 11;
it defaults to 12. */
/* MAXSTRUC The maximum size (in chars) which a single data structure can
be on this platform. This defaults to 1MB (i.e. no limit for
practical purposes). In practice I know of no game files that
require any structures bigger than about 30K. */
/* LOWMEM Define this if you are low on memory. At the moment this
only saves a few K.*/
/* PORTSTR Is the string describing this particular port.
e.g. #define PORTSTR "OrfDOS Port by R.J. Wright" */
/* UNIX_IO if you have Unix-like low level file I/O functions.
(MS-DOS, for example, does). This speeds up the reading
of the large game data files on some platforms */
/* force16 is used purely for debugging purposes, to make sure that
everything works okay even with 16-bit ints */
/* #define force16 */
#define DOHASH
/* This works with Borland C; don't know about other DOS C compilers */
#ifdef MSDOS
#define FAR far
#define strcasecmp(s1,s2) stricmp(s1,s2)
#define NEED_STRN_CMP
#define fix_ascii 0 /* DON'T translate IBM character set */
#define HAVE_SLEEP
#define BUFF_SIZE (16*1024L)
#define CBUF_SIZE (20000L)
#define UNIX_IO
#define MAXSTRUC (64L*1024L) /* DOS 64K Limit */
#define FAST_FIXSIGN
#define PORTSTR "DOS Version"
#endif
#ifdef LINUX
#define LINUX_COLOR
#define fix_ascii 1 /* Don't translate IBM character set */
#define HAVE_TPARAM
#define UNIX
#define HAVE_STRDUP
#define BUFF_SIZE (1024L*1024L)
#define MAXSTRUC (1024L*1024L) /* If we're asking for more than 1 MB, something
is wrong. */
#define CBUF_SIZE (20000L)
#define FAST_FIXSIGN
/* #define SORT_META*/ /* This doesn't work yet */
#define PORTSTR "Linux Version"
#endif
#ifdef SUN
#define NO_TERMCAP_H
#define UNIX
#define BUFF_SIZE (1024L*1024L)
#define MAXSTRUC (1024L*1024L)
#define CBUF_SIZE (20000L)
#define PORTSTR "UNIX Version"
#endif
#ifdef AMIGA
#define NEED_STR_CMP
#define NEED_STRN_CMP
#undef HAVE_STRDUP
#define REPLACE_GETFILE
#define FAST_FIXSIGN
#define BUFF_SIZE (256L*1024L)
#define CBUF_SIZE (20000L)
#define UNIX_IO
#define PORTSTR "Amiga Version by David Kinder"
#define READFLAG O_RDONLY
#endif
#ifdef PLAIN
#define NEED_STR_CMP
#define NEED_STRN_CMP
#define BUFF_SIZE 0
#define CBUF_SIZE (5000L)
#define MAXSTRUC (32L*1024L) /* As I recall, 32K is the minimum required by
the ANSI standard */
#define PORTSTR "Pure ANSI C version"
#endif
/* __GNUC__ */
/* ------------------------------------------------------------------- */
/* DEFAULTS FOR "PLATFORM SPECIFIC" DEFINES */
#ifdef __POSIX__
#ifndef UNIX
#define UNIX
#endif
#endif
#ifdef UNIX
#define HAVE_SLEEP
#define UNIX_IO
#endif
#ifdef __STRICT_ANSI__
#define NEED_STR_CMP
#define NEED_STRN_CMP
#ifdef HAVE_STRDUP
#undef HAVE_STRDUP
#endif
#endif
#ifndef fix_ascii
#define fix_ascii 1 /* Translate IBM character set by default */
#endif
#ifndef BUFF_SIZE
#ifdef LOWMEM
#define BUFF_SIZE 0 /* i.e. unbuffered */
#else
#define BUFF_SIZE (32L*1024L) /* 32K */
#endif
#endif /* BUFF_SIZE */
#ifndef MAXSTRUC
#define MAXSTRUC (1024L*1024L)
#endif
#ifndef HASHBITS
#ifdef LOWMEM
#define HASHBITS 11 /* 2K entries */
#else
#define HASHBITS 12 /* 4K entries in hash table */
#endif
#endif /* HASHBITS */
#ifndef FAR
#define FAR /* Define FAR to be blank */
#endif
/* ------------------------------------------------------------------- */
/* FILENAME EXTENSIONS */
/* These are the various filename extensions for the different data files.*/
#ifndef DA1
#define DA1 ".da1" /* General info (text file) */
#define DA2 ".da2" /* Rooms */
#define DA3 ".da3" /* Items */
#define DA4 ".da4" /* Creatures */
#define DA5 ".da5" /* Commands, headers */
#define DA6 ".da6" /* Commands, code (Master's Ed only) */
#define DSS ".d$$" /* Description strings */
#define pTTL ".ttl" /* Title file */
#define pINS ".ins" /* Instruction file */
#define pVOC ".voc" /* Menu vocabulary file */
#define pCFG ".cfg" /* Game configuration file */
#define pOPT ".opt" /* Interface specification file */
#define pHNT ".hnt" /* Popup hint file; not used yet. */
#endif
/* ------------------------------------------------------------------- */
/* GLOBAL FLAGS */
/* Many of the following should be made into command line options */
/* #define AGT_16BIT */ /* Force interpreter to use 16-bit qunatities */
/* #define DUMP_VLIST */ /* Dump out the verb list info */
/* #define USE_CMD_INDEX */ /* Read in metacommand index data for objects */
/* #define DEBUG_ENCRYPT */ /* Turn on debugging of encryption routine */
#define def_DIAG 1 /* Print out diagnostic data? */
#define def_interp_arg 1 /* Decipher arguments to opcodes? */
#define def_debug_da1 0
/* used to analyse .DA1 files of new gamefile versions */
#define def_RAW_CMD_OUT 0 /*Print CMDs out raw, undecoded; sometimes useful
when trying to understand new gamefile version */
#define def_ERR_LEVEL 2 /* Level of error reporting. */
/* 0== almost none */
/* 1== Report possibly serious conditions */
/* 2== Report any fall from perfection */
#define SS_GRAIN 1024 /* Granularity of size request for static string
array (to avoid calling rrealloc too often) */
#define SYN_GRAIN 32 /* Granularity of requests for synonym array; this
is in units of sizeof(word) */
#define MAX_BADTOK 10 /* How many bad tokens to report before giving
up */
/* ------------------------------------------------------------------- */
/* DEFINES OF GLOBAL PARAMETERS */
/*
None of these are used any more, but I leave them here for reference
#define MAX_ROOM 300
#define MAX_NOUN 300
#define MAX_CREAT 200
#define MAX_CMD 1500
#define MAX_QUEST 100
#define MAX_MSG 1000
#define MAX_PICT 250
#define ABS_MAX_REC_CMD 34
#define MAX_OBJ (MAX_ROOM+MAX_NOUN+MAX_CREAT)
#define SYNCNT 15
*/
#define FORMAT_CODE 0xFF /* Character used for special formatting codes:
--in 1.8x games, it designates bold
--in AGX+ games, it will prefix format codes
--otherwise it designates black (replacing
0, which has obvious problems) */
#define LAST_TEXTCODE 8 /* Last ascii code to be used for text attributes */
#define NUM_ERR 185 /* Number of standard error messages */
#define MAX_SUB 15 /* Maximum number of subroutines */
#define MAX_USTR 25 /* Maximum number of user strings */
#define MAX_PIX 30
#define MAX_FLAG_NOUN 33
#define BASE_VERB 58 /* Number of built in verbs-- this number
includes ANY, which is verb 0. */
#define DVERB 50 /* Number of real dummy_verbs */
#define DUMB_VERB (DVERB+MAX_SUB) /* Number of dummy verbs and subroutines */
#define AUX_VERB 14 /* Additional verbs supported by the interpreter */
#define MAX_VERBS (BASE_VERB+DUMB_VERB)
#define TOTAL_VERB (BASE_VERB+DUMB_VERB+AUX_VERB)
/* The following numbers refer to the ideal code we are translating into,
not the paramaters for the actual data file we're reading. */
#define MAX_TOKEN_ID 250 /* Upper limit on legal (raw) token values.
Doesn't need to be exact. */
#define MAX_COND 118
#define START_ACT 1000 /* First action code */
#define PREWIN_ACT 1113 /* Last action code before WinGame */
#define WIN_ACT 2000 /* Value of win opcode: this and later opcodes
will be moved up to make room for more action
tokens. */
#define END_ACT (WIN_ACT+2) /* Lowest command-terminating action code */
#define MAX_ACT (WIN_ACT+4) /* Highest action code */
/* ------------------------------------------------------------------- */
/* DEFINITIONS OF SPECIAL DATA TYPES */
/* These should by platform-independent. */
#ifdef force16 /* This is for debugging purposes */
#define int short int
#endif
typedef unsigned char uchar;
typedef signed char schar;
typedef short integer; /* Should be a 16+-bit signed numeric type */
typedef unsigned long int32; /* Should be a 32+-bit unsigned numeric type */
typedef char tline[81]; /* Both of these must include terminating null */
typedef char words[25]; /* ...23 in classic, 16 in master's */
typedef short word; /* Pointer into dictionary */
typedef short slist; /* Index into synlist marking beginning of this
synonym list. [SYNCNT]
list of word pointers -- eg synonyms */
typedef uchar bool;
typedef char filename[10]; /* Datatype used for picture, sound, etc. names*/
/* ------------------------------------------------------------------- */
/* DATA STRUCTURE DEFINITIONS */
/* All of the internal data structures used to store the contents of the */
/* game file... */
typedef struct {
long start,len;
} descr_ptr;
typedef struct {
char *opcode;
integer argnum;
integer arg1,arg2;
} opdef; /* Opcode table entry */
/* This is the data type for opcode correction entries */
typedef struct {
integer old,new; /* Old and new values. */
} cmd_fix_rec;
typedef cmd_fix_rec *fix_array;
typedef struct {
char *name; /* [31] */
int32 flag_noun_bits,PIX_bits; /* Master's Ed. only */
slist replacing_word; /* List of words to be replaced */
word replace_word; /* Word that does replacing */
word autoverb; /* Verb automatically executed on entry to room */
integer path[13];
integer key;
integer nouns_inside; /* # nouns inside */
integer contents; /* Used internally by the interpreter; not read in
from the game file */
integer points;
integer light; /* Object that lights room; 0=none needed, 1=any */
integer pict,initdesc;
bool seen, locked_door;
bool end, win, killplayer;
} room_rec;
typedef struct {
char *shortdesc; /* tline */
char *position; /* 23 characters in position for classic ed, 31 for ME */
slist syns; /* List of synonyms */
word name, adj;
word pos_prep, pos_name; /* Used internally by the interpreter */
/* pos_prep==-1 means use noun.position */
integer nearby_noun; /* Noun this noun is behind */
integer num_shots;
integer points;
integer weight, size;
integer key;
integer initdesc,pict;
integer nouns_inside; /* Number of nouns inside */
integer location; /* 1=carried, 1000=worn */
integer contents, next; /* Used internally by the interpreter; not read in
from the game file */
uchar sing_plur;
bool something_pos_near_noun; /* Anybody behind us? */
bool has_syns;
bool pushable, pullable, turnable, playable, readable;
bool on, closable, open, lockable, locked, edible, wearable;
bool drinkable, poisonous, movable, light;
bool shootable;
bool win;
/* words related; related_name */
} noun_rec;
typedef struct {
char *shortdesc; /* tline */
slist syns;
word name;
word adj;
integer location;
integer contents, next; /* Used internally by the interpreter; not read in
from the game file */
integer weapon; /* Killed by this */
integer points;
integer nouns_inside; /* Number of nouns it's carrying */
integer counter; /* How many times has player been nasty to it? */
integer threshold, timethresh, timecounter;
integer pict,initdesc;
bool has_syns;
bool groupmemb;
bool hostile;
uchar gender;
} creat_rec;
typedef struct {
integer verbnum; /* Contains either actor or verb information. */
word verbcmd, nouncmd, objcmd, prep; /* prep only in ME games */
integer *data; /* MaxSizeCommand */
integer cmdsize; /* Number of commands */
/* integer ptr; */ /* In ME games-- see below for replacement */
} cmd_rec;
/* FRS=file record size; these are the sizes to be allocated to the buffer
used to read in the various records from the files; they should be at
least as big as the worst case scenario. */
#define FRS_ROOM 220
#define FRS_NOUN 310
#define FRS_CREAT 240
#define FRS_CMD 150
/* ------------------------------------------------------------------- */
/* GLOBAL VARIABLES */
global uchar DIAG, interp_arg, debug_da1, RAW_CMD_OUT;
global int ERR_LEVEL;
global bool mars_fix;
global long game_sig; /* 2-byte quantity used to identify game files */
/* (It's declared long to avoid overflow problems when
computing it) */
global long MAX_CMD_SIZE;
global long start_room, treas_room, ressurect_room, max_lives, max_score;
global long start_time, delta_time;
global uchar score_mode, statusmode;
global bool debug_mode, freeze_mode, milltime_mode, bold_mode;
global long maxroom, maxnoun, maxcreat, last_cmd;
global long MaxQuestion, first_room, last_room, first_noun, last_noun,
first_creat, last_creat;
global long first_message, last_message, num_verbs;
global long numglobal; /* Number of global nouns */
global long maxpict, maxpix, maxfont, maxsong;
global word FAR flag_noun[MAX_FLAG_NOUN],*globalnoun;
global word FAR pix_name[MAX_PIX];
global filename *pictlist,*pixlist,*fontlist,*songlist;
global tline *userstr; /*[MAX_USTR];*/
global descr_ptr intro_ptr;
global descr_ptr FAR err_ptr[NUM_ERR];
global descr_ptr *msg_ptr; /* [MAX_MSG];*/
global descr_ptr *help_ptr, *room_ptr, *special_ptr; /*[ROOM] */
global descr_ptr *noun_ptr, *text_ptr, *turn_ptr, /* [NOUN] */
*push_ptr, *pull_ptr, *play_ptr;
global descr_ptr *talk_ptr, *ask_ptr, *creat_ptr; /* [CREAT] */
global descr_ptr *quest_ptr, *ans_ptr; /* [MAX_QUEST] */
global tline *question, *answer; /* [MAX_QUEST] */
global int ver,aver; /* ver: 0=unknown, 1=small, 2=big, 4=masters1.5 */
global slist FAR synlist[MAX_VERBS+1];
global bool anyspecialcmd;
/* All of the following are allocated dynamically */
global room_rec *room; /* [MAX_ROOM]; */
global creat_rec *creature; /* [MAX_CREAT]; */
global noun_rec *noun; /* [MAX_NOUN]; */
global cmd_rec *command;
global word FAR sub_name[MAX_SUB]; /* Dictionary id's of all subroutines */
global words *dict;
global int dp; /* Dictionary pointer: number of words in dict */
global char *static_str; /*Static string space */
global long strptr; /* Pointer to end of used space in above */
global long ss_size; /* Current size of static string space */
global word *syntbl; /* Synonym list space */
global slist synptr; /* Points to end of used space */
global slist syntbl_size;
global short verbptr[TOTAL_VERB],verbend[TOTAL_VERB];
/*The following are all set to NULL after agtread finishes. */
global long *cmd_ptr; /* ME only;Points to cmd start locs in gamefile.*/
global long *room_name,*noun_sdesc,*noun_pos,*creat_sdesc;
/* ------------------------------------------------------------------- */
/* SYMBOLIC CONSTANTS */
/* A-Version Codes */
#define AGT10 1 /* SPA-- token encoding isn't supported */
#define AGT118 2 /* TAMORET, PORK II */
#define AGT12 3 /* SOS,... */
#define AGTCOS 4 /* COSMOS and SOGGY: enhanced versions of 1.3x */
#define AGT135 5 /* By far the most common version; includes practically
every version of Classic AGT from 1.19 to 1.7 */
#define AGT182 6 /* 1.8x support hasn't been tested */
#define AGT183A 7
#define AGT183 8
#define AGT15 9 /* HOTEL -- token encoding not known */
#define AGT15F 10 /* MDTHIEF-- " " " " */
#define AGTME10 11 /* CLIFF2, ELF20 */
#define AGTME15 12 /* WOK */
#define AGTME155 13 /* TJA */
#define AGTME16 14 /* also includes v1.56 */
#define AGTMAST AGTME16
#define AGTCLASS AGT15F /* Dividing line between master's ed and classic */
#define AGT18 AGT182 /* Defines lowest 1.8x version */
#define AGT18MAX AGT183 /* Defines the highest 1.8x version */
/* Argument Data Types (for the opcode table) */
#define AGT_UNK 0 /* Unknown argument type */
/* The following can all mix and match in various ways and so are
put together as powers of two. */
#define AGT_NONE 1 /* 0 is allowed */
#define AGT_SELF 2 /* 1 is allowed */
#define AGT_WORN 4 /* 1000 is allowed */
#define AGT_ROOM 8 /* A room # is allowed */
#define AGT_ITEM 16 /* An item # is allowed */
#define AGT_CREAT 32 /* A creature # is allowed */
/* The rest of the values are always distinct; they never mix and so
they can be given simple consecutive indices */
#define AGT_NUM 128
#define AGT_FLAG 129
#define AGT_VAR 130
#define AGT_QUEST 131 /* Question */
#define AGT_MSG 132 /* Message */
#define AGT_STR 133 /* String */
#define AGT_CNT 134 /* Counter */
#define AGT_DIR 135 /* Direction */
#define AGT_SUB 136 /* Subroutine */
#define AGT_PIC 137 /* Picture */
#define AGT_PIX 138 /* Room picture */
#define AGT_FONT 139
#define AGT_SONG 140
#define AGT_ROOMFLAG 141
/* Verb flags for verbflag[]; these should be powers of 2 */
#define VERB_TAKEOBJ 1
#define VERB_META 2
/* ------------------------------------------------------------------- */
/* FUNCTION PROTOTYPES AND INITIALIZED TABLES */
/* In AGTDATA.C */
void init_dict(bool); /* 1=set of verblist, 0=don't */
void reinit_dict(void);
void free_dict(void);
word search_dict(const char*);
word add_dict(const char*);
int verb_code(word);
void addsyn(word);
char *objname(int i);
void agtwarn(const char*,int elev);
void agtnwarn(const char*,int,int elev);
void fatal(const char*);
void sort_cmd(void);
extern char trans_ibm[];
extern opdef cond_def[], act_def[], end_def[]; /* Tables of opcodes */
global words *verblist; /* List of prexisting words, intialized by init_dict */
extern fix_array FIX_LIST[];
extern char exitname[13][4];
extern char verstr[][10],averstr[][10];
extern char version_str[],portstr[];
global slist FAR auxsyn[TOTAL_VERB]; /* Built in synonym list */
global slist FAR preplist[TOTAL_VERB];
global uchar FAR verbflag[TOTAL_VERB]; /* Verb flags; see above */
/* In AGTREAD.C */
void open_descr(char*);
void close_descr(void);
tline *read_descr(long start,long len);
void free_descr(tline *p);
void readagt(char *gamename,bool diag);
void free_all_agtread(void); /* Cleans up everything allocated in agtread
should only be called at the very end of
the program */
/* In or used by AGTDBG.C */
global bool *dbgflagptr;
global long *dbgvarptr;
global short *dbgcntptr;
void debugout(const char *s);
void argout(int dtype, int dval);
/* AGTTEST.C or INTERFACE.C */
void writeln(const char *s);
/* In RMEM.C */
/* File routines */
long file_size(FILE *f); /* Size of an open binary file */
FILE *openfile(char *fname,char *ext,char *err,bool ferr);
void readln(FILE *f, char *buff, int n); /* Read a line from a 'text' file */
/* (None of the following routines are at all reentrant) */
long buffopen(char *fname,char *ext,int minbuffsize,char *rectype,int recnum);
/* Open file for our buffered routines and make it our current file;
returns the record size. Prints out error message on failure
rectype="noun","room",etc.; recnum=expected # of objects in file */
uchar *buffread(long index);
/* seek to index*recsize, read buff_rsize bytes, return pointer to a
buffer with them. */
void buffclose(void); /* Close the current file */
/* Memory management variables and routines */
global bool rm_trap; /* Trap memory allocation failures? */
global bool rm_acct; /* Turn on rmem accounting, to locate memory leaks */
global long rfree_cnt, ralloc_cnt; /* # of allocs/frees since acct turned on */
global long rm_size, rm_freesize; /* These hold worst case values */
long get_rm_size(void); /* These get the current values */
long get_rm_freesize(void);
void *rmalloc(long size);
void r_free(void *p);
#define rfree(p) (r_free(p),p=NULL) /* Traps errors & catch memory leaks */
void *rrealloc(void *p,long size);
char *rstrdup(const char *s);
/* String utilities */
char *concdup(const char *s1,const char *s2); /* Concacate and duplicate */
#ifdef NEED_STR_CMP
int strcasecmp(const char *s1,const char *s2);
#endif
#ifdef NEED_STRN_CMP
int strncasecmp(const char *s1,const char *s2,size_t n);
#endif
/* The fixsign.. routines put together unsigned bytes to form signed ints */
#ifndef FAST_FIXSIGN
short fixsign16(uchar n1,uchar n2);
long fixsign32(uchar n1,uchar n2,uchar n3,uchar n4);
#else
#define fixsign16(u1,u2) ( (u1) | ((u2)<<8) )
#define fixsign32(u1,u2,u3,u4) ( ((long)u1) | (((long)u2)<<8) | \
(((long)u3)<<16) | (((long)u4)<<24) )
#endif
#ifdef global_defined_agtread
#undef global
#undef global_defined_agtread
#endif